<?php
   
   class MyDB extends SQLite3
   {
      function __construct()
      {  
      $name=$_POST['student_name'];
      $xuehao=$_POST['student_xuehao'];
      if($name==""){
          echo "姓名未填   ";
      }
      if($xuehao==""){
          echo "学号未填";
      }
      echo "<br>";
        echo $name.$xuehao."<br>";
         $this->open('student.db');
      }
   }
   $db = new MyDB();
   if(!$db){
      echo $db->lastErrorMsg();
   } else {
      echo "Opened database successfully\n";
   }
   $name=$_POST['student_name'];
   $xuehao=$_POST['student_xuehao'];
   if(strlen($name)>=1){
  $sql =<<<EOF
      SELECT * from students where 姓名 like '%{$name}%';
EOF;
     }
     
   else if(strlen($xuehao)>=1){
  $sql =<<<EOF
      SELECT * from students where 学号 like '%{$xuehao}%';
EOF;
    }
    
    else{
$sql =<<<EOF
       SELECT * from students';
EOF;
     }
      
   echo "<table border='2'>
<tr>
<th>序号</th>
<th>学号</th>
<th>姓名</th>
<th>性别</th>
<th>民族</th>
<th>学院</th>
<th>班级</th>
<th>宿舍号</th>
</tr>";


$ret = $db->query($sql);
   while($row = $ret->fetchArray(SQLITE3_ASSOC) ){
      echo "<tr>";
      echo "<td>". $row['序号'] . "</td>\n";
      echo "<td>". $row['学号'] ."</td>\n";
      echo "<td>". $row['姓名'] ."</td>\n";
      echo "<td>". $row['性别'] . "</td>\n";
      echo "<td>". $row['民族'] ."</td>\n";
      echo "<td>". $row['学院'] ."</td>\n";
      echo "<td>". $row['班级'] . "</td>\n";
      echo "<td>". $row['宿舍号'] ."</td>\n";
      echo "</tr>";
   }
   echo "</table>";
   echo "Operation done successfully\n";
   $db->close();
?>